export const NORMAL_SUCCESS = 1000
export const NORMAL_ERROR = 1001
export const LOGIN_ERROR = 1002
export const AUTH_ERROR = 1003
export const VERIFY_ERROR = 1004
export const CODE_ERROR = 1005
export const AUTH_ERROR_CODE = 3602

export const ERROR_LEVEL_WARNING = 'warning'

export function genSuccessData(
  data,
  msg = ''
) {
  return {
    code: NORMAL_SUCCESS,
    msg: msg || 'OK',
    data,
  }
}

export function genErrorData(
  msg,
  code = NORMAL_ERROR,
  errorLevel = ERROR_LEVEL_WARNING
) {
  if (code === 0) {
    code = NORMAL_SUCCESS
  }

  if (code === CODE_ERROR) {
    msg = '[Code Error]：' + msg
  }

  return {
    code,
    msg,
    errorLevel: errorLevel,
  }
}

export function genErrorDataEmpty(
  msg,
  code = NORMAL_SUCCESS,
  errorLevel = ERROR_LEVEL_WARNING
) {
  if (!msg) {
    msg = '未查询到该条数据，请检查该数据是否存在'
  }

  return genErrorData(msg, code, errorLevel)
}

export function checkDataOk(data) {
  if (data.code === 1000) {
    return true
  }

  return false
}